﻿using System.Collections.Generic;

namespace TemperatureConverter
{
    public class Temperature
    {
        private double _value;
        
        public enum TemperatureType
        {
            C,
            K,
            F,
            N
        };
      
        private static readonly Dictionary<TemperatureType, double> AbsoluteZero = new Dictionary<TemperatureType, double>
            {
            {TemperatureType.C, -273.15},
            {TemperatureType.K, 0},
            {TemperatureType.F, -459.67},
            {TemperatureType.N, -90.14}
        };

        public Temperature(double initValue, TemperatureType initType)
        {
            Type = initType;
            Value = initValue;
        }

        public double Value
        {
            get { return _value; }
            set
            {
                if (value < AbsoluteZero[Type]) 
                    throw new TemperatureUnlimitedException();
                _value = value;
            }
        }

        public TemperatureType Type { get; set; }

        public override bool Equals(object obj)
        {
            if (obj == null) return false;          
            var temp = obj as Temperature;
            if (temp == null) return false;
            return (Value == temp.Value) && (Type == temp.Type);
        }

        public bool Equals(Temperature obj)
        {
            return (Value==obj.Value)&&(Type==obj.Type);
        }
    }
}
